<%--
  Created by IntelliJ IDEA.
  User: 10153
  Date: 2025/3/27
  Time: 下午7:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"  isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>登录成功页面</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.js"></script>
    <script>
        var msg = "${msg}";
        if (msg != ""){
            alert(msg);
        }
    </script>
</head>
<body>
<h1>图书管理界面</h1>
    <button onclick ="addBook()">添加图书</button>
    <table id="t1" cellpadding="20px" cellspacing="0px" border="1px">
        <tr>
           <td>id</td>
           <td>书名</td>
           <td>作者</td>
           <td>数量</td>
           <td>按钮</td>
        </tr>

    </table>

    <script>



        function addBook(){
            location.href="/book/toAddBook";
        }




        $(function(){
            $.ajax({
                url:"/load/bookInterface",


                type:"get",

                dataType:"json",

                success:function (data){
                    $("#t1").children().not(":eq(0)").remove();
                    console.log(data);
                    for (var i=0;i<data.length;i++){
                        $("#t1").append("<tr>" +
                            " <td>"+data[i].id+"</td>" +
                            "<td>"+data[i].title+"</td>" +
                            "<td>"+data[i].author+"</td>" +
                            "<td>"+data[i].num+"</td>" +
                            "<td>"+"<button onclick=updateById("+data[i].id+")> "+"修改</button>"
                            +"<button onclick=deleteById("+data[i].id+")> "+"删除</button>"
                            +"</td>"+
                            "</tr>");
                    }
                }

            })

        });

        function deleteById(id) {
            if(confirm("真的要删除吗")){
                alert("删除成功");
                location.href="/book/deleteBook?id="+id;
            }
        }

        function updateById(id) {
                location.href="/book/toUpdateBook?id="+id;
        }
    </script>
</body>
</html>
